/*
 * 描述
 * Created by: litangyu
 * 包含类名列表
 * 版本信息，版本号 v1.0
 * 创建日期 16/9/5
 * 版权声明
*/
package com.foton.logistic.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;

import com.foton.logistic.R;
import com.foton.logistic.util.ResultUtil;
import com.foton.logistic.util.image.fresco.FrescoUtils;
import com.foton.logistic.util.image.fresco.InstrumentedDraweeView;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;


public class ImageGridAdapter extends BaseAdapter {

    private List<String> mImgUrlList;
    private final Context mContext;
    int imageHeight;

    public ImageGridAdapter(Context context, List<String> urlList,int imageHeight) {
        this.mContext = context;
        this.mImgUrlList = urlList;
        this.imageHeight = imageHeight;
    }

    @Override
    public int getCount() {
        return mImgUrlList.size();
    }

    @Override
    public Object getItem(int position) {
        return mImgUrlList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.ft_adapter_image_grid, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.imageview.getLayoutParams().height = imageHeight;
        FrescoUtils.displayImage(holder.imageview, ResultUtil.judgeImagePath(mImgUrlList.get(position)),imageHeight,imageHeight);
        return convertView;
    }

    class ViewHolder {
        @InjectView(R.id.base_fresco_fitcenter_imageview)
        InstrumentedDraweeView imageview;
        @InjectView(R.id.ft_adapter_image_grid_layout)
        LinearLayout layout;

        public ViewHolder(View itemView) {
            ButterKnife.inject(this, itemView);
        }
    }

}
